package com.fejal.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
public class TurmaOfertaDisciplina implements Serializable, Cloneable {


	private static final long serialVersionUID = -1291980661968495930L;

	@Id
	@GeneratedValue (strategy = GenerationType.AUTO)
	private int codigoTurmaOfertaDisciplina;
	
	@OneToOne	
	@JoinColumn(name = "codigoDisciplina")
	private Disciplina disciplina;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "codigoTurmaOferta", insertable = true, updatable = true)
	@Fetch(FetchMode.JOIN)
	@Cascade(CascadeType.SAVE_UPDATE)
	private TurmaOferta turmaOferta;	
	
	@OneToMany(mappedBy="turmaOfertaDisciplina", fetch = FetchType.LAZY)
	@Cascade({   
        CascadeType.ALL,   
        CascadeType.DELETE_ORPHAN})   
	private Collection<ProfessorDisciplina> professorDisciplina;

	@OneToMany(mappedBy="turmaOfertaDisciplina", fetch = FetchType.EAGER)
	@Cascade({   
        CascadeType.ALL,   
        CascadeType.DELETE_ORPHAN})   
	private Collection<Horario> horarios;
	
	public TurmaOfertaDisciplina(){
		
	}

	public TurmaOferta getTurmaOferta() {
		return turmaOferta;
	}

	public void setTurmaOferta(TurmaOferta turmaOferta) {
		this.turmaOferta = turmaOferta;
	}

	public int getCodigoTurmaOfertaDisciplina() {
		return codigoTurmaOfertaDisciplina;
	}

	public void setCodigoTurmaOfertaDisciplina(int codigoTurmaOfertaDisciplina) {
		this.codigoTurmaOfertaDisciplina = codigoTurmaOfertaDisciplina;
	}

	public Disciplina getDisciplina() {
		return disciplina;
	}

	public void setDisciplina(Disciplina disciplina) {
		this.disciplina = disciplina;
	}

	public Collection<ProfessorDisciplina> getProfessorDisciplina() {
		return professorDisciplina;
	}

	public void setProfessorDisciplina(
			Collection<ProfessorDisciplina> professorDisciplina) {
		this.professorDisciplina = professorDisciplina;
	}

	public Collection<Horario> getHorarios() {
		return horarios;
	}

	public void setHorarios(Collection<Horario> horarios) {
		this.horarios = horarios;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + codigoTurmaOfertaDisciplina;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TurmaOfertaDisciplina other = (TurmaOfertaDisciplina) obj;
		if (codigoTurmaOfertaDisciplina != other.codigoTurmaOfertaDisciplina)
			return false;
		return true;
	}
	
	public TurmaOfertaDisciplina retornaClone () {   
	      try {   
	        return (TurmaOfertaDisciplina)this.clone();   
	      }   
	      catch (CloneNotSupportedException ex) {   
	        ex.printStackTrace();   
	        return null;   
	      }   
	    }	
	
}
